﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PPI.Entities.Enumerator;
using PPI.Entities.Inspections;

namespace PPI.Entities.Utility
{
    public class EUtility_Asset_XMissionStructure : EBaseAsset
    {
        private EUtility m_Utility;
        private EUtility_Contact m_Contact;
        private EUtility_Project m_Project;
        private List<EBasePosition> m_VisitInspections;
        private List<EBasePosition> m_VisitGps;


        public EUtility Utility
        {
            get { return m_Utility; }
            set { m_Utility = value; }
        }
        public EUtility_Contact Contact
        {
            get { return m_Contact; }
            set { m_Contact = value; }
        }
        public EUtility_Project Project
        {
            get { return m_Project; }
            set { m_Project = value; }
        }

        public List<EBasePosition> VisitInspections
        {
            get { return m_VisitInspections; }
            set { m_VisitInspections = value; }
        }
        public List<EBasePosition> VisitGps
        {
            get { return m_VisitGps; }
            set { m_VisitGps = value; }
        }

        public EUtility_Asset_XMissionStructure()
        :base()
        {
            m_Utility = new EUtility();
            m_Contact = new EUtility_Contact();
            m_Project = new EUtility_Project();
            m_VisitInspections = new List<EBasePosition>();
            m_VisitGps = new List<EBasePosition>();
        }

        public EUtility_Asset_XMissionStructure(Int32 id)
        :this()
        {
            Id = id;
        }

        public override string GetPlacemarkId()
        {
            return "Asset_" + Id.ToString();
        }

        public override string GetIcon()
        {
            return PPI.Constants.K_ASSETICON;
        }

        public override string GetHtmlName()
        {
            return "Asset " + Id.ToString();
        }

        public override string GetHtmlPlacemark()
        {
            StringBuilder _Shtml = new StringBuilder();
            _Shtml.AppendLine("<table style='font-family:Verdana; font-size:10px;' border='0'>");
            _Shtml.AppendLine(" <tr>");
            _Shtml.AppendLine("     <td ><b>Asset [" + Id + "]</b></td>");
            _Shtml.AppendLine(" </tr>");
            _Shtml.AppendLine(" <tr>");
            _Shtml.AppendLine("     <td>");
            _Shtml.AppendLine("         <table>");
            _Shtml.AppendLine("             <tr>");
            _Shtml.AppendLine("                 <td>Latitude:</td>");
            _Shtml.AppendLine("                 <td>" + Latitude + "</td>");
            _Shtml.AppendLine("             </tr>");
            _Shtml.AppendLine("             <tr>");
            _Shtml.AppendLine("                 <td>Longitude:</td>");
            _Shtml.AppendLine("                 <td>" + Longitude + "</td>");
            _Shtml.AppendLine("             </tr>");
            _Shtml.AppendLine("             <tr>");
            _Shtml.AppendLine("                 <td>Altitude:</td>");
            _Shtml.AppendLine("                 <td>" + Altitude+ "</td>");
            _Shtml.AppendLine("             </tr>");
            _Shtml.AppendLine("         </table>");
            
            foreach (EBasePosition gp in m_VisitGps)
            {
                _Shtml.AppendLine(RenderHtmlGps((EVendor_Visit_XMissionStructure) gp));
            }
            foreach (EBasePosition inspection in m_VisitInspections)
            {
                _Shtml.AppendLine(RenderHtmlInspection((EInspectionStructure) inspection));
            }
            _Shtml.AppendLine("     </td>");
            _Shtml.AppendLine(" </tr>");
            _Shtml.AppendLine("</table>");
            return _Shtml.ToString();
        }


        private string RenderHtmlGps(EVendor_Visit_XMissionStructure structure)
        {
            StringBuilder _html = new StringBuilder();
            _html.AppendLine("<table>");
            _html.AppendLine("  <tr>");
            _html.AppendLine("      <td>" + String.Format("Structure Type : {0}", DatabaseTypes.GPS) + "");
            _html.AppendLine("      <td>" + String.Format("Structure ID : {0}", structure.Id) + "");
            _html.AppendLine("  </tr>");
            _html.AppendLine("</table>");
            _html.AppendLine(structure.GetHtmlPlacemark());

            return _html.ToString();
        }

        private string RenderHtmlInspection(EInspectionStructure structure)
        {
            StringBuilder _html = new StringBuilder();
            _html.AppendLine("<table>");
            _html.AppendLine("  <tr>");
            _html.AppendLine("      <td>" + String.Format("Structure Type : {0}", DatabaseTypes.Inspection) + "");
            _html.AppendLine("      <td>" + String.Format("Structure ID : {0}", structure.Id) + "");
            _html.AppendLine("  </tr>");
            _html.AppendLine("</table>");
            _html.AppendLine(structure.GetHtmlPlacemark());
            return _html.ToString();
        }
    }
}
